param(
    [string] $url = $(Read-Host -Prompt "Enter Url"),
    [string] $template
)

Add-PSSnapin Microsoft.SharePoint.PowerShell | Out-Null

if(($site = get-spweb $url -ErrorAction SilentlyContinue) -ne $null)
{
    Write-Warning "Removing web @ $url"
    Remove-spweb -Identity $url -Confirm:$false
}

Write-Host "Creating new web @ $url"
if(![string]::IsNullOrEmpty($template))
{
    $web = New-SPWeb -Url "$url"
    if($web -ne $null)
    {
        $web.ApplyWebTemplate($template)
    }
}